﻿namespace IceCS.DataStructure.Core.BinaryTree
{
    /// <summary>
    /// 二叉树节点
    /// </summary>
    public class BTreeNode<T>
    {
        /// <summary>
        /// 节点数据
        /// </summary>
        public T Data { get; set; }

        /// <summary>
        /// 左子节点
        /// </summary>
        public BTreeNode<T> LeftChildNode { get; set; }
        /// <summary>
        /// 右子节点
        /// </summary>
        public BTreeNode<T> RightChildNode { get; set; }
        /// <summary>
        /// 双亲节点
        /// </summary>
        public BTreeNode<T> ParentNode { get; set; }

        /// <summary>
        /// 是否是叶子节点
        /// </summary>
        public bool IsLeaf
        {
            get
            {
                return LeftChildNode == null && RightChildNode == null;
            }
        }

        /// <summary>
        /// 构造函数
        /// </summary>
        public BTreeNode()
        {
            Data = default;
            LeftChildNode = null;
            RightChildNode = null;
            ParentNode = null;
        }

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="data">节点数据</param>
        /// <param name="leftChildNode">左子节点</param>
        /// <param name="rightChildNode">右子节点</param>
        public BTreeNode(T data, BTreeNode<T> leftChildNode, BTreeNode<T> rightChildNode) : this()
        {
            Data = data;
            LeftChildNode = leftChildNode;
            RightChildNode = rightChildNode;
        }

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="leftChildNode">左子节点</param>
        /// <param name="rightChildNode">右子节点</param>
        public BTreeNode(BTreeNode<T> leftChildNode, BTreeNode<T> rightChildNode) : this()
        {
            LeftChildNode = leftChildNode;
            RightChildNode = rightChildNode;
        }

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="data">节点数据</param>
        public BTreeNode(T data) : this()
        {
            Data = data;
        }

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="data">节点数据</param>
        /// <param name="parentNode">双亲节点</param>
        public BTreeNode(T data, BTreeNode<T> parentNode) : this()
        {
            Data = data;
        }
    }
}
